package com.dahua.messagesyncsh.business.mitsubishi.controller;

import feign.Contract;
import feign.Feign;
import feign.Request;
import feign.Retryer;
import feign.jackson.JacksonDecoder;
import feign.jackson.JacksonEncoder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@Configuration
public class FeignConfig {

    @Value("${mitsubishi.feign.url}")
    private String url;


    @Bean
    public Contract useFeignAnnotations() {
        return new Contract.Default();
    }

    @Bean
    public Mitsubishi toMitsubishi() {
        return Feign.builder()
                .encoder(new JacksonEncoder())
                .decoder(new JacksonDecoder())
                .options(new Request.Options(6, TimeUnit.SECONDS,
                        12, TimeUnit.SECONDS,
                        false ))
                .retryer(new Retryer.Default(1000, 2000, 3))
                .target(Mitsubishi.class, url);
    }
}